﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Adex;
using System.Transactions;
using SubSonic;
using System.Configuration;
using System.Web.Services;
using MediaMonitor.Common;

namespace MediaMonitor.Users
{
    public partial class NewDesign : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {


            if (!IsPostBack)
            {
                //hdnComentIDMaster.Value = Request.Cookies["User"]["UserID"].ToString();
            }
        }
        protected void lnkLastNewsAlert_Click1(object sender, EventArgs e)
        {
            DataTable dt = SPs.NewaAlertLast(Request.Cookies["User"]["Company"].ToString(), "last", "", "").GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                    switch (Design)
                    {
                        case 1:
                            Response.Redirect("all-newsalertLast.aspx?Code=last");
                            break;
                        case 2:
                            Response.Cookies["Last"]["TV"] = "TV";
                            Response.Cookies["Last"]["Radio"] = "Radio";
                            Response.Cookies["Last"]["Press"] = "Press";
                            Response.Cookies["Last"]["Internet"] = "Internet";
                            Response.Redirect("NewAll-newsalertLastMultiMedia.aspx?Code=last");
                            break;
                        case 3:
                            Response.Redirect("Report-LastNewAlert.aspx");
                            break;
                    }
                }
                else
                {
                    Response.Cookies["Last"]["TV"] = "TV";
                    Response.Cookies["Last"]["Radio"] = "Radio";
                    Response.Cookies["Last"]["Press"] = "Press";
                    Response.Cookies["Last"]["Internet"] = "Internet";
                    Response.Redirect("NewAll-newsalertLastMultiMedia.aspx?Code=last");
                }

            }
            else
            {
                string script = "alert(\"No Record Found For Your Search!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
            }
        }
        protected void lnkPendingNewsAlert_Click1(object sender, EventArgs e)
        {

            DataTable dt = SPs.NewaAlertPending(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), "", "pending", "").GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                    switch (Design)
                    {
                        case 1:
                            Response.Redirect("All-NewsAlertPending.aspx?Code=pending");
                            break;
                        case 2:
                            Response.Cookies["Last"]["TV"] = "TV";
                            Response.Cookies["Last"]["Radio"] = "Radio";
                            Response.Cookies["Last"]["Press"] = "Press";
                            Response.Cookies["Last"]["Internet"] = "Internet";
                            Response.Redirect("NewAll-newsalertPendingMultiMedia.aspx?Code=pending");
                            break;
                        case 3:
                            ReportFuncs rpt = new ReportFuncs();
                            DataTable dtPending = rpt.GetReport_NewsAlertOnDate(Convert.ToInt32(Request.Cookies["User"]["UserID"]));
                            string date = dtPending.Rows[0]["LoginDate"].ToString();
                            Response.Redirect("report-LastNewAlert.aspx?Date=" + date + "&Code=Padding");
                            break;
                    }
                }
                else
                {
                    Response.Cookies["Last"]["TV"] = "TV";
                    Response.Cookies["Last"]["Radio"] = "Radio";
                    Response.Cookies["Last"]["Press"] = "Press";
                    Response.Cookies["Last"]["Internet"] = "Internet";
                    Response.Redirect("NewAll-newsalertPendingMultiMedia.aspx?Code=pending");
                }


            }
            else
            {
                string script = "alert(\"No Record Found For Your Search!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
            }
        }
        protected void lnkToday_Click1(object sender, EventArgs e)
        {

            DataTable dt = SPs.NewaAlertToday(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), DateTime.Now.ToShortDateString() + " 00:00:00.000", "Today", "", "").GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                    switch (Design)
                    {
                        case 1:
                            Response.Redirect("All-NewsAlertToday.aspx?Code=Today");
                            break;
                        case 2:
                            Response.Cookies["Last"]["TV"] = "TV";
                            Response.Cookies["Last"]["Radio"] = "Radio";
                            Response.Cookies["Last"]["Press"] = "Press";
                            Response.Cookies["Last"]["Internet"] = "Internet";
                            Response.Redirect("NewAll-newsalertTodayMultiMedia.aspx?Code=Today");
                            break;
                        case 3:
                            ReportFuncs rpt = new ReportFuncs();
                            DataTable dtToday = rpt.GetReport_NewsAlertOnDate(Convert.ToInt32(Request.Cookies["User"]["UserID"]));
                            string date = dtToday.Rows[0]["LoginDate"].ToString();
                            Response.Redirect("report-Todaynewalert.aspx?Date=" + date);
                            break;
                    }
                }
                else
                {
                    Response.Cookies["Last"]["TV"] = "TV";
                    Response.Cookies["Last"]["Radio"] = "Radio";
                    Response.Cookies["Last"]["Press"] = "Press";
                    Response.Cookies["Last"]["Internet"] = "Internet";
                    Response.Redirect("NewAll-newsalertTodayMultiMedia.aspx?Code=Today");
                }

            }
            else
            {
                string script = "alert(\"No Record Found For Your Search!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
            }
        }
        protected void lnkSearchforNewsAlert_Click1(object sender, EventArgs e)
        {
            DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
            if (dt1.Rows.Count > 0)
            {
                int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                switch (Design)
                {
                    case 1:
                        Response.Redirect("report-newsalert-filter.aspx?Code=All");
                        break;
                    case 2:
                        Response.Redirect("NewAll-newsalert-Filter.aspx?Code=All");
                        break;
                    case 3:
                        Response.Redirect("report-newsalert-filter2.aspx?Code=");
                        break;
                }
            }
            else
            {
                Response.Redirect("NewAll-newsalert-Filter.aspx?Code=All");
            }

        }

        protected void btnSearch_click(object sender, EventArgs e)
        {
            //TransactionOptions options = new TransactionOptions();
            //options.Timeout = new TimeSpan(0, 2, 0);
            //options.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
            //TransactionScope ts = new TransactionScope(TransactionScopeOption.Suppress, options);
            //try
            //{
            //    SharedDbConnectionScope conn = new SharedDbConnectionScope(ConfigurationManager.ConnectionStrings["DBAdex"].ToString());
            //    try
            //    {
            try
            {
                TblConfiguración prLog = new TblConfiguración();
                prLog.UserID = Convert.ToInt32(Request.Cookies["User"]["UserID"]);
                prLog.DateX = DateTime.Now;

                if (chkDesign1.Checked)
                {
                    prLog.Design = 1;
                }

                else if (chkDesign2.Checked)
                {
                    prLog.Design = 2;
                }

                else if (chkDesign3.Checked)
                {
                    prLog.Design = 3;
                }
                else
                    prLog.Design = 0;
                if (chkLast.Checked)
                    prLog.Page = "last";
                else if (chkPending.Checked)
                    prLog.Page = "pending";
                else if (chkToday.Checked)
                    prLog.Page = "today";
                else if (chkSearch.Checked)
                    prLog.Page = "search";
                else
                    prLog.Page = "";
                //prLog.Save();

                //ts.Complete();
                if (prLog.Design == 0)
                {
                    string script = "alert(\"Please select atleast one design!\");";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
                    ModalPopupExtender2.Show();
                    return;
                }
                else
                {
                    int str = Convert.ToInt32(SPs.ConfiguraciónInsert(prLog.UserID, prLog.DateX, prLog.Design.ToString(), prLog.Page).ExecuteScalar());
                    string script = "alert(\"Design changed successfully!\");";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
                    ModalPopupExtender2.Hide();
                }


            }
            catch (Exception exception)
            {
                // ex2 = exception;
                // ts.Dispose();
                //   conn.Dispose();
            }
            //}
            //    finally
            //    {

            //        ((IDisposable)conn).Dispose();

            //    }
            //}
            //finally
            //{

            //    ((IDisposable)ts).Dispose();

            //}


        }
        protected void lnkConfiguración_Click(object sender, EventArgs e)
        {
            DataTable dt = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString())).GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {

                switch (dt.Rows[0]["Design"].ToString())
                {
                    case "1":
                        chkDesign1.Checked = true;
                        chkDesign2.Checked = false;
                        chkDesign3.Checked = false;
                        break;
                    case "2":
                        chkDesign1.Checked = false;
                        chkDesign2.Checked = true;
                        chkDesign3.Checked = false;
                        break;
                    case "3":
                        chkDesign1.Checked = false;
                        chkDesign2.Checked = false;
                        chkDesign3.Checked = true;
                        break;
                }
                switch (dt.Rows[0]["Page"].ToString())
                {
                    case "last":
                        chkLast.Checked = true;
                        chkPending.Checked = false;
                        chkToday.Checked = false;
                        chkSearch.Checked = false;
                        break;
                    case "pending":
                        chkLast.Checked = false;
                        chkPending.Checked = true;
                        chkToday.Checked = false;
                        chkSearch.Checked = false;
                        break;
                    case "today":
                       chkLast.Checked = false;
                       chkPending.Checked = false;
                        chkToday.Checked = true;
                        chkSearch.Checked = false;
                        break;
                    case "search":
                         chkLast.Checked = false;
                       chkPending.Checked = false;
                       chkToday.Checked = false;
                        chkSearch.Checked = true;
                        break;
                }
            }
            ModalPopupExtender2.Show();
        }
        protected void btnCancelPopup_Click(object sender, EventArgs e)
        {
            chkSearch.Checked = false;
            chkPending.Checked = false;
            chkLast.Checked = false;
            chkDesign3.Checked = false;
            chkDesign2.Checked = false;
            chkDesign1.Checked = false;
            chkToday.Checked = false;
            ModalPopupExtender2.Hide();
        }
    }
    public class Bind1
    {
        public Bind1()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        private string _ID;
        private string _UserID;
        private string _RFDate;
        private string _Page;
        public int _IsActive { get; set; }
        public string ID
        {
            set { _ID = value; }
            get { return _ID; }
        }
        public string UserID
        {
            set { _UserID = value; }
            get { return _UserID; }
        }

        public string RFDate
        {
            set { _RFDate = value; }
            get { return _RFDate; }
        }
        public string Page
        {
            set { _Page = value; }
            get { return _Page; }
        }
        public int IsActive
        {
            set { _IsActive = value; }
            get { return _IsActive; }
        }
    }
}
